package cn.kpi.service.workassessment.impl;

import cn.kpi.dao.workassessment.WorkKPIDao;
import cn.kpi.entity.workassessment.WorkKPItemEntity;
import cn.kpi.service.workassessment.IWorkKPIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;
import java.util.Map;

/**
 * 队伍考核打分
 *
 * @author lex
 * @create 2018-06-20-11:22
 */
@Controller
public class WorkKPIServiceImpl implements IWorkKPIService {


    @Autowired
    private WorkKPIDao workKPIDao;


    @Override
    public List<Map> GetWorkKPIMapByTempIdAndColumns(Long tempid, String columns) throws Exception {
        try {
            return workKPIDao.GetWorkKPIMapByTempIdAndColumns(tempid, columns);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    @Override
    public int InsertWorkKPItemBatch(Long templateid, List<WorkKPItemEntity> list) throws Exception {
        try {
            int result = workKPIDao.DeleteWorkKPItem(templateid);
            result += workKPIDao.InsertWorkKPItemBatch(list);
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//回滚事物
            return -1;
        }
    }

    @Override
    public List<WorkKPItemEntity> getWeight(Long templateid) {
        return workKPIDao.getWeights(templateid);
    }


}
